<?php

require_once(B_DIR . '/_res/_smarty/Smarty.class.php');

class tpl extends Smarty {

	public function __construct() {
		parent::__construct();
		
		//$this->template_dir	= B_DIR.'/_tmp/template_dir';
		$this->template_dir	= B_DIR . '/' ;

		$this->compile_dir	= B_DIR . '/_res/dir_compile';

		$this->cache_dir	= B_DIR . '/_res/dir_cache';

		$this->left_delimiter	= '{-';
		$this->right_delimiter	= '-}';


		$this->assign('sess_name' , session_name());
		$this->assign('sess_id' , session_id());

		$this->assign_by_ref('_GET' , $_GET);
		$this->assign_by_ref('_POST' , $_POST);
	}



	public function & display( $file = false) {
		if( empty( $file ) ){
			$file	= basename($_SERVER['SCRIPT_NAME']);
			$file	= substr($file, 0, -4);
			$file	= B_DIR . '/' . $file . '.tpl.htm';
		}
		parent::display($file);
		return $this;
	}

	public function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null){
		$_compile_dir_sep =  $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
		$_return = $auto_base . DIRECTORY_SEPARATOR;

		if(isset($auto_id)) {
			$auto_id	= str_replace('%7C', $_compile_dir_sep,  urlencode($auto_id) );
			$_return	.= $auto_id . $_compile_dir_sep;
		}

		if(isset($auto_source)) {
			$_filename	= str_replace('/', '~', $auto_source); //urlencode(
			$_crc32		= sprintf('%08X', crc32($auto_source));
			$_crc32		= substr($_crc32, 0, 2) . $_compile_dir_sep .
						substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32;
			$_return	.=  $_filename . '_%%' . $_crc32 . '%%';
		}
		return $_return;
	}
}
?>
